package wjh.blog.util;

public class PageView {

	private int count;
	private int pageNum;
	private int size =5;
	private int pageStart =1;
	private int pageEnd=5;
	public PageView(int count,int pageNum) {
		this.count=count;
		this.pageNum=pageNum;
	}
	
	public void setSize(int size) {
		this.size = size;
	}
	
	public int getStart(){
		if(pageNum-size/2<=0){
			pageStart =1;
		}else {
			pageStart=pageNum-size/2;
		}
		if(count-pageStart<size){
			pageStart = count-(size-1);
		}
		
		return pageStart;
	}
	
	public int getPageNum() {
		return pageNum;
	}
	
	public int getNext(){
		if(pageNum+1>=count){
			return count;
		}else{
			return pageNum+1;
		}
	}
	
	public int getBefore(){
		if(pageNum-1<=1){
			return 1;
		}else{
			return pageNum-1;
		}
	}
	public int getEnd(){
		pageStart = getStart();
		if(pageStart+size-1>count){
			pageEnd = count;
		}else{
			pageEnd=pageStart+size-1;
		}
		
		return pageEnd;
	}
}
